<template>
  <div class="login-page">
    <el-card class="box-card">
      <div class="header">
        <img
          style="height: 54px"
          src="https://slwl-admin.itheima.net/static/img/logo1.33ef7fa0.png"
          alt=""
        />
      </div>
      <el-form ref="form" :model="form" :rules="rules">
        <!-- 用户名 -->
        <el-form-item prop="account">
          <img
            src="…oTLbed3OX1+UKlCvwmlbgJXZ+J2u7PF4BAAAAAElFTkSuQmCC"
            alt=""
          />
          <el-input
            prefix-icon="icon iconfont icon-yonghu-copy"
            v-model="form.account"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input
            show-password
            prefix-icon="icon iconfont icon-tianchongxing--copy"
            v-model="form.password"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <!-- 验证码 -->
        <el-form-item prop="key">
          <el-input
            prefix-icon="icon iconfont icon-yanzhengma-copy"
            v-model="form.code"
            placeholder="请输入验证码"
          >
          </el-input>
          <!-- 验证码图片 -->
          <span class="code-image" @click="getImg">
            <img :src="url" alt="" />
          </span>
        </el-form-item>
        <!-- 按钮 -->
        <el-form-item class="tc">
          <el-button
            style="width: 100%; height: 50px; margin-top: 30px"
            type="primary"
            @click="submit"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 视频 -->
    <!-- <div class="videoContainer">
      <video
        class="fullscreenVideo"
        id="bgVid"
        playsinline=""
        autoplay="autoplay"
        muted="muted"
        loop="loop"
      >
        <source
          src="https://slwl-admin.itheima.net/static/media/video.3cf57b17.mp4"
          type="video/mp4"
        />
      </video>
    </div> -->
  </div>
</template>

<script>
import { getLogin } from "@/api/login";
import axios from "axios";
export default {
  name: "LoginIndex",
  data() {
    return {
      url: "",
      form: {
        account: "shenlingadmin",
        password: "123456",
        key: "7",
        code: "",
      },
      rules: {
        account: [
          {
            required: true,
            message: "请输入用户名",
          },
          {
            min: 5,
            max: 13,
            message: "请输入5-11位字符",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
          },
          {
            pattern: /^\w{5,11}$/,
            message: "请输入5-11位密码",
          },
        ],
        key: [
          {
            required: true,
            message: "请输入验证码",
          },
        ],
      },
    };
  },
  computed: {},
  created() {
    this.getImg();
  },
  methods: {
    // 验证码
    async getImg() {
      // console.log(1);
      const { data } = await axios({
        url: "https://slwl-geteway.itheima.net/manager/captcha?key=7",
        responseType: "blob",
      });
      // 通过URL.createObjectURL(blob)可以获取当前文件的一个内存URL
      const url = URL.createObjectURL(data);
      this.url = url; //验证码路径
      console.log(url);
      console.log(data);
    },
    // 登录
    async submit() {
      // try {
      const res = await getLogin(this.form);
      // console.log(res.data.token.token);
      // 存入token
      this.$store.commit("user/setToken", res.data.token.token);
      // 跳转主页面
      this.$router.push("/");
      this.$message.success("登录成功");
    },
    reset() {
      // 表单初始值
      this.$refs.form.resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.code-image {
  display: inline-block;
  vertical-align: top;
  width: 80px;
  height: 37px;
  cursor: pointer;
  margin-left: 10px;
  position: absolute;
  right: 10px;
  top: 7px;
  img {
    width: 70px;
    height: 30px;
  }
}
::v-deep .icon-yanzhengma-copy:before {
  font-size: 24px;
}
::v-deep .el-input__icon {
  margin-left: 10px;
  font-size: 18px;
}
::v-deep .el-input--prefix .el-input__inner {
  padding-left: 45px;
}
::v-deep .el-input__inner {
  height: 50px;
}
.header {
  margin-bottom: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-size: cover;
}
.login-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-size: cover;
  .el-card {
    width: 450px;
    height: 467px;
    margin: 0 auto;
    border-radius: 10px;
    ::v-deep .el-card__header {
      // background-color: rgb(114, 124, 245, 1);
      text-align: center;
      color: white;
      height: 80px;
      font-size: 18px;
      line-height: 40px;
    }
  }
  .el-form {
    padding: 0 20px;
  }
  .tc {
    text-align: center;
    width: 100%;
  }
}
.videoContainer {
  position: fixed;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: -100;
  // 满屏
  video {
    width: 100%;
    height: 100%;
    object-fit: fill;
  }
}

// .videoContainer:before {
//   content: "";
//   position: fixed;
//   right: 0;
//   min-width: 100%;
//   min-height: 100%;
//   width: auto;
//   height: auto;
//   z-index: -999;
// }
</style>
